package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.sgb.kjwl.R;
import com.sgb.kjwl.callback.OnItemClickListener;
import com.sgb.kjwl.model.entity.pick.EnterpriseBiddingDetailEntity5;
import com.sgb.kjwl.view.ui.adapter.pick.holder.PickEnterpriseMultiltemViewHolder;
import com.swgk.core.base.CallBack;

import java.util.ArrayList;
import java.util.List;

public class PickEnterpriseMultiItemAdapter extends RecyclerView.Adapter<PickEnterpriseMultiltemViewHolder> {


    private CallBack callBack;
    private Context mContext;

    public List<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> getmList() {
        return mList;
    }

    public void setmList(List<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> mList) {
        this.mList = mList;
    }

    private List<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> mList;
    private List<PickEnterpriseMultiltemViewHolder> holderList = new ArrayList<>();

    public PickEnterpriseMultiItemAdapter(Context context, List<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> list, CallBack callBack) {
        this.mContext = context;
        this.mList = list;
        this.callBack = callBack;
    }

    public void setData(List<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> list) {
        if (list.size() != 0) {
            mList.addAll(list);
        }
        notifyDataSetChanged();
    }

    public void setNewData(List<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> list) {
        if (list.size() != 0) {
            mList.clear();
            mList.addAll(list);
        }
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public PickEnterpriseMultiltemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PickEnterpriseMultiltemViewHolder(
                mContext,
                (ViewGroup) LayoutInflater.from(parent.getContext())
                        .inflate(
                                R.layout.pick_enterprise_multiltem_item,
                                parent,
                                false),
                callBack,onItemClickListener);
    }

    @Override
    public void onBindViewHolder(@NonNull final PickEnterpriseMultiltemViewHolder holder, int position) {
        final EnterpriseBiddingDetailEntity5.TenderingAsksEntity bean = mList.get(position);
        holder.bind(position, bean, this);
        holderList.add(holder);
    }

    public PickEnterpriseMultiltemViewHolder getHolder(int pos) {
        return holderList.get(pos);
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    //点击事件的回调
    private OnItemClickListener<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> onItemClickListener;

    //设置回调监听
    public void setOnItemClickListener(OnItemClickListener<EnterpriseBiddingDetailEntity5.TenderingAsksEntity> listener) {
        this.onItemClickListener = listener;
    }
}
